﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="~/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="~/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="~/css/site.css" media="all">
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">修改密码</div>
            <div class="layui-card-body" style="padding: 15px;">
                <form class="layui-form" lay-filter="form-group">
                    <div class="layui-form-item">
                        <label class="layui-form-label">原密码</label>
                        <div class="layui-input-block">
                            <input type="text" name="txtOld" lay-verify="pass" autocomplete="off" placeholder="请输入原密码" class="layui-input w300" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-block">
                            <input type="text" name="txtNew" lay-verify="pass" autocomplete="off" placeholder="请输入新密码" class="layui-input w300" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-block">
                            <input type="text" name="txtNew2" lay-verify="pass" autocomplete="off" placeholder="请确认新密码" class="layui-input w300" value="">
                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="" lay-filter="form-page">修改</button>
                                <button class="layui-btn layui-btn-primary" id="closePage">取消</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="~/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form'], function () {
            var $ = layui.$
                , layer = layui.layer
                , form = layui.form;

            form.render(null, 'form-group');

            /* 自定义验证规则 */
            form.verify({
                pass: [/(.+){6,12}$/, '密码必须6到12位']
            });

            ///* 监听提交 */
            form.on('submit(form-page)', function (data) {
                console.log(data.field);
                $.ajax({
                    type: "post",
                    url: '/Admin/UpdatePassword',
                    data: data.field,
                    //async: false,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 1000) {
                            layer.alert(res.msg, function (index) {
                                top.location.href = '/admin/login';//do something
                                layer.close(index);
                            });
                        }
                        else {
                            layer.msg(res.msg, { icon: 5 });
                        }
                    }
                });
                //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                return false;
            });

            //取消
            $("#closePage").on('click', function () {
                parent.layui.admin.events.closeThisTabs();
            });

        });
    </script>
</body>
</html>
